package com.tencet.servlet;

import com.tencet.entity.Recharge;
import com.tencet.service.Impl.AccountTwoServiceImpl;
import com.tencet.service.Impl.ReChargeServiceImpl;
import com.tencet.service.RechargeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.UUID;

/**
 * @author: stand    @date: 2022/7/21 10:19
 * @description:
 */
@WebServlet("/recharge")
public class RechargeServlet2 extends HttpServlet {
    RechargeService rechargeService = new ReChargeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer balance = Integer.valueOf(req.getParameter("balance"));
        String card_num2 = (String) req.getSession().getAttribute("secondAccountNumber");
        String paypassword = req.getParameter("paypassword");
        AccountTwoServiceImpl accountTwoService = new AccountTwoServiceImpl();
        Integer balance1 = accountTwoService.getBalance(card_num2);
        int sum = balance1 + balance;
        String phone = (String) req.getSession().getAttribute("phone");
        Recharge recharge = new Recharge(UUID.randomUUID()+"",card_num2,phone,new Timestamp(System.currentTimeMillis()),balance);
        rechargeService.addBean(recharge);

        int i = rechargeService.addBalance(sum, card_num2);
        req.getRequestDispatcher("account_index.jsp").forward(req,resp);
    }
}